package com.ruoyi.quotation.controller;


import com.ruoyi.quotation.domain.QuoQuote;
import com.ruoyi.quotation.service.QuoQuoteService;
import com.ruoyi.quotation.vo.QuoteEngineeringVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/quote")
public class QuoQuoteController {

    @Autowired
    private QuoQuoteService quoQuoteService;

    // 1. 根据姓名查询
    @GetMapping("/byName")
    public List<QuoQuote> getByName(@RequestParam String name) {
        return quoQuoteService.getQuotesByName(name);
    }

    // 2. 联表查询详情
    @GetMapping("/details/{id}")
    public QuoteEngineeringVO getDetails(@PathVariable Integer id) {
        return quoQuoteService.getQuoteWithEngineering(id);
    }

    // 3. 修改报价
    @PutMapping("/update")
    public String updateQuote(@RequestBody QuoQuote quote) {
        return quoQuoteService.updateQuote(quote) ? "更新成功" : "更新失败";
    }

    // 4. 新增报价
    @PostMapping("/add")
    public String addQuote(@RequestBody QuoQuote quote) {
        return quoQuoteService.addQuote(quote) ? "新增成功" : "新增失败";
    }

    // 5. 删除报价
    @DeleteMapping("/delete/{id}")
    public String deleteQuote(@PathVariable Integer id) {
        return quoQuoteService.deleteQuote(id) ? "删除成功" : "删除失败";
    }
}
